__author__ = 'mud'
from redis_helper import RedisHelper

code = input('输入口令 >_：')
if code == 'exit':
    print('拜拜 >_')
    exit()
else:
    print('主人欢迎回来~，现在进入编辑模式！')
    db = RedisHelper()
    while True:
        code = input('>_: ')
        code = code.strip()
        if not code:
            print('不能为空哦！')
        elif code == 'exit':
            print('主人，要走了吗，拜拜~')
            exit()
        else:
            cmdList = code.split(' ')
            if len(cmdList) < 2:
                reply = db.get(cmdList[0])
                print(reply)
            elif len(cmdList) == 2:
                if cmdList[0].startswith('g'):
                    reply = db.get(cmdList[1])
                    print(reply)
                else:
                    print('啊，主人，不懂您的意思，请重新输入……')
            else:
                if cmdList[0].startswith('s') or cmdList[0] == '令':
                    reply = db.put(cmdList[1], cmdList[2])
                    print(reply)
